import { create } from 'zustand'

import { LocalEnum, ThemeColorPresets } from '#/enum'

type Platform = {
  lang: LocalEnum
  theme: 'light' | 'dark'
  primaryColor: ThemeColorPresets
  actions: {
    setLang: (lang: LocalEnum) => void
    setTheme: (mode: 'light' | 'dark') => void
    setPrimaryColor: (value: ThemeColorPresets) => void
  }
}

const usePlatformStore = create<Platform>(set => {
  return {
    lang: LocalEnum.zh_CN,
    theme: 'light',
    primaryColor: ThemeColorPresets.Default,
    actions: {
      setLang: lang => {
        set({ lang })
      },
      setTheme: mode => {
        set({ theme: mode })
      },
      setPrimaryColor: value => {
        set({ primaryColor: value })
      }
    }
  }
})

export const usePlatformLang = () => usePlatformStore(state => state.lang)
export const usePlatformTheme = () => usePlatformStore(state => state.theme)
export const usePlatformPrimaryColor = () => usePlatformStore(state => state.primaryColor)
export const usePlatformActions = () => {
  // console.log("usePlatformActions");
  return usePlatformStore(state => state.actions)
}
export { usePlatformStore }
